﻿var vm = new Vue({
    el: "#PAGE_MODEL",
    data: {
        //删除时传入的ID参数
        DetailId: "",

        //查询的关键字
        keyword: "",

        //列表
        VmQualificationDetails: [],

        //单个类
        VmQualificationDetail: {

            //明细ID
            DetailId: "",

            //企业资质主类ID
            Qid: "",

            //企业资质--项目类型
            Type: "",

            //资质要求
            Details_Require: "",

            //业务范围
            Details_Range: "",

            //明细表备注
            Details_Remark: ""
        },

        //索引
        pageindex: 0,

        //每页记录数
        pagesize: 10,

        //总页数
        pagecount: 1,

        //分页标志
        pagesizes: [10, 20, 30, 40, 50],

        //当前页
        currentpage: 1,

        //总页数
        total: 0,

    },
    methods: {
        //跳转到新建的页面
        NewQualificationDetail: function () {
            location.href = URLs.URL_GOTO_NEWQUALIFICATIONDETAIL;
        },

        //增加企业资质明细记录
        addQualificationDetail: function () {

            var self = this;

            if (self.VmQualificationDetail.Details_Require.length > 0 && self.VmQualificationDetail.Details_Range.length > 0) {

                var data = self.VmQualificationDetail;

                $.ajax({
                    url: URLs.URL_ADD_QUALIFICATIONDETAIL,
                    type: "POST",
                    data: JSON.stringify({ VmQualificationDetail: data }),
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.ISOK) {
                            bootbox.alert("保存记录成功!");
                        } else {
                            bootbox.alert("保存错误，错误代码：<br />" + data.MESSAGE);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        bootbox.alert("保存记录基本信息时，系统运行错误，错误代码：<br />" + textStatus);
                        $.jqhideloading();
                    },
                    beforeSend: function () {
                        $.jqshowloading();
                    },
                    complete: function () {
                        $.jqhideloading();
                    }
                });

            } else {
                bootbox.alert("您还没填写完整信息，请继续填写");
            }
        },

        //删除企业资质明细记录
        deleteQualificationDetail: function (DetailId) {

            var self = this;

            bootbox.confirm("确定要删除选定的记录吗？", function (result) {
                if (result) {
                    $.ajax({
                        type: "POST",
                        url: URLs.URL_DELETE_QUALIFICATIONDETAIL,
                        dataType: "json",
                        data: JSON.stringify({
                            DetailId: DetailId
                        }),
                        contentType: 'application/json; charset=utf-8',
                        success: function (data) {
                            if (data.ISOK) {
                                bootbox.alert("成功删除指定数据！");
                                self.getQualificationDetailListindex();
                            } else {
                                bootbox.alert("删除数据错误：" + data.MESSAGE);
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            bootbox.alert("系统错误！");
                            //初始化错误结束，允许按钮，并将图标恢复原状
                        },
                        beforeSend: function () {
                            $.jqshowloading();
                        },
                        complete: function () {
                            $.jqhideloading();
                        }
                    });
                } else {
                    return 0;
                }
            });
        },

        //当前页多少条记录
        handleCurrentChange: function (index) {
            var self = this;
            //选中的第几页
            self.getQualificationDetailListCurrent(index);
            console.log(index);
        },

        //查询企业资质记录明细列表---handleCurrentChange
        getQualificationDetailListCurrent: function (index) {
            var self = this;
            self.pageindex = index - 1;

            $.ajax({
                url: URLs.URL_GET_QUALIFICATIONDETAILLIST,
                type: "POST",
                dataType: "json",
                data: JSON.stringify({
                    keyword: $("#keyword").val(),
                    pageindex: self.pageindex,
                    pagesize: self.pagesize,
                }),
                contentType: 'application/json; charset=utf-8',
                success: function (data) {
                    if (data.ISOK) {

                        self.VmQualificationDetails = data.VmQualificationDetails;

                        //绑定查询条件
                        self.pageindex = data.PageIndex;
                        self.pagecount = data.PageCount;
                        self.total = data.RecordCount;

                        // bootbox.alert("当前  self.pageindex = " + self.pageindex +"  self.pagecount = " + self.pagecount + "self.total = " + self.total);
                    } else {
                        bootbox.alert("查询信息错误，错误代码：<br />" + data.MESSAGE);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    bootbox.alert("系统运行错误（获取记录列表），错误代码：<br />" + textStatus);
                    $.jqhideloading();
                },
                beforeSend: function () {
                    $.jqshowloading();
                },
                complete: function () {
                    $.jqhideloading();
                }
            });
        },

        //每页多少条记录
        handleSizeChange: function (size) {
            var self = this;
            self.currentpage = 1;
            self.pagesize = size;
            self.pageindex = 0;
            self.getQualificationDetailListindex();
            console.log(size);
        },

        //查询企业资质记录明细列表--handleSizeChange
        getQualificationDetailListindex: function () {
            var self = this;
            $.ajax({
                url: URLs.URL_GET_QUALIFICATIONDETAILLIST,
                type: "POST",
                dataType: "json",
                data: JSON.stringify({
                    keyword: $("#keyword").val(),
                    pageindex: self.pageindex,
                    pagesize: self.pagesize,
                }),
                contentType: 'application/json; charset=utf-8',
                success: function (data) {
                    if (data.ISOK) {

                        self.VmQualificationDetails = data.VmQualificationDetails;

                        //绑定查询条件
                        self.pageindex = data.PageIndex;
                        self.pagecount = data.PageCount;
                        self.total = data.RecordCount;

                        //bootbox.alert("self.pageindex = " + self.pageindex +"  self.pagecount = " + self.pagecount + "self.total = " + self.total);
                    } else {
                        bootbox.alert("查询信息错误，错误代码：<br />" + data.MESSAGE);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    bootbox.alert("系统运行错误（获取记录列表），错误代码：<br />" + textStatus);
                    $.jqhideloading();
                },
                beforeSend: function () {
                    $.jqshowloading();
                },
                complete: function () {
                    $.jqhideloading();
                }
            });
        },

        //修改时候捕捉数据显示在修改页面中
        getDataFromListToUpdate: function (DetailId) {
            var self = this;
            $.ajax({
                url: URLs.URL_GET_ONEQUALIFICATIONDETAIL,
                type: "POST",
                dataType: "json",
                data: JSON.stringify({
                    DetailId: DetailId
                }),
                contentType: 'application/json; charset=utf-8',
                success: function (data) {
                    if (data.ISOK) {

                        self.VmQualificationDetail = data.VmQualificationDetail;

                    } else {
                        bootbox.alert("获取修改信息错误，错误代码：<br />" + data.MESSAGE);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    bootbox.alert("系统运行错误（获取需要修改的这条记录），错误代码：<br />" + textStatus);
                    $.jqhideloading();
                },
                beforeSend: function () {
                    $.jqshowloading();
                },
                complete: function () {
                    $.jqhideloading();
                }
            });
        },

        //修改企业资质明细记录
        UpdateQualificationDetail: function () {
            var self = this;
            //拼凑参数
            var data = self.VmQualificationDetail;
            $.ajax({
                url: URLs.URL_UPDATE_QUALIFICATIONDETAIL,
                type: "POST",
                dataType: "json",
                data: JSON.stringify({
                    VmQualificationDetail: data
                }),
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    if (data.ISOK) {
                        bootbox.alert("修改信息成功!");
                    } else {
                        bootbox.alert("修改信息错误，错误代码：<br />" + data.MESSAGE);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    bootbox.alert("修改信息时，系统运行错误，错误代码：<br />" + textStatus);
                    $.jqhideloading();
                },
                beforeSend: function () {
                    $.jqshowloading();
                },
                complete: function () {
                    $.jqhideloading();
                }
            });
        },

        //查询上一页数据
        pagePrev: function () {
            var self = this;

            if (self.pageindex - 1 >= 0) {
                self.pageindex--;
                self.getQualificationDetailListindex();
            } else {
                bootbox.alert("已经是第一页了！");
            }
        },

        //查询下一页数据
        pageNext: function () {
            var self = this;

            if (self.pageindex + 1 < self.pagecount) {
                self.pageindex++;
                self.getQualificationDetailListindex();
            } else {
                bootbox.alert("已经是最后一页了！");
            }
        },
    },
});